
package com.example.cia.database.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.example.cia.database.mysql.dao.impl.userImpl;

public class userLoginServlet extends HttpServlet{

	/**
	 * 用户登录的Servlet
	 */
	private static final long serialVersionUID = 3504149207961540403L;

	public void doGet(HttpServletRequest request,HttpServletResponse response)
			throws ServletException,IOException{
		int id = Integer.parseInt(request.getParameter("id").toString());
		String password = request.getParameter("password").toString();
		boolean ifSucceed = false;
		userImpl user = new userImpl(); 
		try {
			if(user.login(id, password))
				ifSucceed = true;
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		} catch (SQLException e) {
			e.printStackTrace();
		}
		response.setCharacterEncoding("UTF-8");
		response.setContentType("text/html");
		PrintWriter out = response.getWriter();
		out.print(ifSucceed);
        out.flush();
        out.close();
	}
	
	public void doPost(HttpServletRequest request,HttpServletResponse response)
	        throws ServletException,IOException{
		
	}
}
